import React, {Component} from 'react'
import {ListComponent,ListBox} from '../../../components'
import { Form, Modal, Button } from 'antd';

export default class WorkkqmodalTable extends Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
            rowObj: {},
            isAdd: true
        }
        this.selectRowObj = {};
        this.rowOperation = [
            {
                handleName: 'rowClick',
                showName: '行单击选择事件'
            }
        ];
        //header 操作列表
        this.headerOperation = [

        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'listAreaColumnConfig',
            data: [
                {
                    showName: 'areaId',
                    columnName: 'areaId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '库区编码',
                    columnName: 'areaCode',
                    columnWidth: 130
                }, {
                    showName: '库区描述',
                    columnName: 'areaDesc'
                },
                {
                    showName: '仓库编码',
                    columnName: 'whCode'
                },
                {
                    showName: '区域编码',
                    columnName: 'regionCode'
                }, {
                    showName: '激活标记',
                    columnName: 'activeFlag'
                }, {
                    showName: '创建人',
                    columnName: 'createBy'
                }, {
                    showName: '创建时间',
                    columnName: 'gmtCreate'
                }, {
                    showName: '最后修改人',
                    columnName: 'lastModifiedBy'
                }, {
                    showName: '最后修改时间',
                    columnName: 'gmtModified'
                }
            ]
        };

        //搜索属性配置
        this.searchComponentData = [
            {
                name: 'activeFlag',
                type: 'select',
                optionList:[]
            },{
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin'
            },{
                name:'gmtModified',
                type: 'date',
                maxName:'gmtModifiedMax',
                minName:'gmtModifiedMin'
            }
        ];
    }

    rowHandles = (strHandles, rowObj) => {
        if(strHandles == 'rowClick'){
            this.rowClickHandle(rowObj);
        }
    }

    rowClickHandle = (rowObj) => {
        /*if(rowObj.length === 0){
            this.setState({ rowObj: {}, isAdd: true });
        }else{
            this.setState({ rowObj: rowObj[0].data, isAdd: false });
        }*/
        this.selectRowObj = rowObj[0].data;
        // console.log('点击取到的值',rowObj)
    }
    refreshHandle = () => {
        this.refs.listComponent.refreshHandle();
    }
    showModal = () => {
        this.setState({
            visible: true
        })

        this.selectRowObj = {};

    }
    handleOk = () => {
        this.setState({
            visible: false
        })

        let resultData = {};
        //resultData.value = this.selectRowObj.workareaCode;
        resultData.value = this.selectRowObj.areaCode;
        //resultData.type = 'instock';
        this.props.getkqTableData(resultData);



        //this.props.getTableData(String( this.state.rowObj.workareaId ))
    }
    handleCancel = () => {
        this.setState({
            visible: false
        })
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <Modal
                    style={{top: '20px',maxHeight:'500px'}}
                    visible={this.state.visible}
                    title="自定义表单"
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}              
                    width={'1250px'}
                    footer={[
                        <Button key="back" onClick={this.handleCancel}>取消</Button>,
                        <Button key="submit" type="primary" onClick={this.handleOk}>
                        确定
                        </Button>,
                    ]}
                    maskClosable={false}
            >
                {/*<ListComponent
                    ref = "listComponent"
                    url = '/base/auth/user/list'
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    isRowSingle = "true"
                    subtractHeight = '0'
                    subtractWidth ='145'
                />*/}

                <ListBox
                        ref = 'listLocation'
                        isHideLeft={isHideLeft}
                        tableColumnData = {this.tableColumn}
                        searchComponentData={this.searchComponentData}
                        url = '/base/data/area/list'
                        rowHandles = {this.rowHandles}
                        rowOperation = {this.rowOperation}
                        headerOperation = {this.headerOperation}
                        subtractHeight = '50'
                        isRowSingle = "true"
                />

            </Modal>
        )
    }
}
